package com.DFB.common.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一响应结果集
 *
 * @author crush
 */
@Data
@NoArgsConstructor
@AllArgsConstructor

public class Result<T> {

    //操作代码
    Integer code;

    //提示信息
    String message;

    //结果数据
    T data;

    public Result(ResultCode resultCode) {
        this.code = resultCode.code();
        this.message = resultCode.message();
    }

    public Result(ResultCode resultCode, T data) {
        this.code = resultCode.code();
        this.message = resultCode.message();
        this.data = data;
    }

    public Result(String message) {
        this.message = message;
    }

    public static Result<String> success() {
        return new Result<String>(ResultCode.SUCCESS);
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(ResultCode.SUCCESS, data);
    }

    public static Result<String> error() {
        return new Result<String>(ResultCode.FAIL);
    }

    public static Result<String> error(ResultCode resultCode) {
        return new Result<String>(resultCode);
    }

    public static Result<String> error(String message) {
        return new Result<String>(message);
    }
}
